// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import VueAxios from 'vue-axios'
import store from "./vuex/stroe";

let baseURL = "http://39.106.54.200:8088/"

Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.use(VueAxios,axios);
Vue.prototype.$axios = axios;
Vue.prototype.$store = store;
/* eslint-disable no-new */
Vue.prototype.$post =function post(date){
  return new Promise((resolve, reject) =>{
    axios({
      url : baseURL + date.url,
      data : (!date.hasOwnProperty('data'))?{}:date.data,
      //data : date.data,
      method: (!date.hasOwnProperty('method'))?'post':date.method,
      headers:{
        'token' : store.getters.getToken
      }
    }).then(res => {
      if(date.url == "login"){
        resolve(res.data)
      }
      else {
        if (res.data.code !== 0) {
          if(res.data.code != 403){
            alert(res.data.msg)
          }else{
            alert("无访问权限或登录过期！")
            router.push({
              path : '/'
            })
          }
        }
        else {
          resolve(res.data.data)
        }
      }
    }).catch(err =>{
        reject(err)
    })
  });
}
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  store
})
